function Y = deconv_batch(X, filter, stride)
border = 1;

[Xhei0, Xwid0, ~] = size(X);
X = padarray(X, [border, border], 'replicate');
[Xhei, Xwid, Xnum] = size(X);
fsize = size(filter);

Yhei = Xhei * stride;
Ywid = Xwid * stride;
Y = zeros(Yhei + fsize(1) - 1, Ywid + fsize(2) - 1, Xnum);
idx = 1 - stride;
for i = 1 : Xhei
    idx = idx + stride;
    pp1 = idx : idx + fsize(1) - 1;
    idy = 1 - stride;
    for j = 1 : Xwid
        idy = idy + stride;
        pp2 = idy : idy + fsize(2) - 1;
        x = X(i, j, :);
        Y(pp1, pp2, :) = Y(pp1, pp2, :) + reshape(filter(:)*x(:)', [fsize Xnum]);
    end
end

Yhei = Xhei0 * stride;
Ywid = Xwid0 * stride;
temp = (fsize + 1)/2 + stride * border;
Y = Y(temp : Yhei + temp - 1, temp : Ywid + temp - 1, :);